<template>
  <div>
    <!-- 顶部组件 -->
    <header-nav></header-nav>

    <!-- 轮播图 -->
    <div class="banner">
      <div class="imgs">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
          <van-swipe-item v-for="(item, index) in imgs" :key="index">
            <img :src="item.pic" />
          </van-swipe-item>
        </van-swipe>
      </div>
    </div>
    <!-- 每日推荐 -->

    <!-- 推荐歌单 -->
    <div class="remLists">
      <div class="title">推荐歌单</div>
      <div class="content">
        <ul>
          <li v-for="item in Personalizedr" :key="item.id">
            <router-link
              tag="div"
              :to="'/recommend/recommendlist?id=' + item.id"
              class="img"
            >
              <img :src="item.picUrl" />
            </router-link>
            <p>{{ item.name }}</p>
            <span
              ><i class="iconfont icon-erji"></i
              >{{ item.playCount | playCountData }}</span
            >
          </li>
        </ul>
      </div>
    </div>

    <!-- 最新音乐 -->
    <div class="result">
      <div class="title">最新音乐</div>
      <div class="musicList">
        <dd
          v-for="(item, index) in getNewSongListApi"
          :key="item.id"
          @click="newId(item.id)"
        >
          <h1>{{ index + 1 }}</h1>
          <div class="info">
            <div class="text">
              <h2>{{ item.name }}</h2>
              <h3>
                <span v-for="value in item.song.artists" :key="value.id">{{
                  value.name
                }}</span>
              </h3>
            </div>

            <div class="iconfont icon-liebiao-bofang bofang"></div>
          </div>
        </dd>
      </div>
    </div>

    <!-- mv
    <div>
      <div class="video">
        <div class="title">最新MV</div>
        <div class="content">
          <ul>
            <li
              v-for="item in getPersonalized"
              :key="item.id"
              @click="mvid(item.id)"
            >
              <div class="img">
                <img :src="item.cover" />
              </div>
              <p>{{ item.name }}</p>
              <span>
                <i class="iconfont icon-MV">{{
                  item.playCount | playCountData
                }}</i>
              </span>
            </li>
          </ul>
        </div>
      </div>
    </div> -->
    <!-- 推荐视频 -->
    <div class="boad">
      <div class="swiper-container swiper-container02 video">
      <div class="title">最新MV</div>
      <div class="swiper-wrapper list content">
        <ul>
          <li v-for="item in video" :key="item.id">
            <router-link
              tag="div"
              class="swiper-slide item img"
              :to="'/recommend/videolist?id=' + item.data.vid"

            >
             
                <img :src="item.data.coverUrl" alt="" />
              </router-link>
              <p>{{ item.data.title }}</p>
              
           
          </li>
        </ul>
      </div>
      <!-- <div class="swiper-pagination swiper-pagination"></div> -->
    </div>
    </div>
    
  </div>
</template>

<script>
import { getPersonalized } from "../api/video";
import {
  getBanner,
  getPersonalizedr,
  getNewSongListApi,
  getVideoTimelineRecommend,
} from "../api/recommend"; //推荐歌单 轮播图数据  推荐歌曲
import headerNav from "../components/base/headerNav.vue"; //头部组件
// https://3.swiper.com.cn/demo/index.html
import Swiper from "swiper";

export default {
  data() {
    return {
      getPersonalized: [],
      getDetail: [],
      imgs: null,
      Personalizedr: null,
      num: null,
      getNewSongListApi: null, //推荐歌曲
      show: false, //是否弹出
      video: [], //推荐视频
    };
  },
  methods: {
    //获取推荐视频
    getVideoTimelineRecommendFun() {
      getVideoTimelineRecommend({ offset: 10 }).then((item) => {
        // console.log(item);
        this.video = item.datas;
        // console.log(this.video);
      });
    },
    //弹出层
    showPopup() {
      this.show = true;
    },
    mvid(id) {
      console.log("mvid", id);
    },
    //获取最新MV
    getPersonalizedFun() {
      getPersonalized().then((data) => {
        console.log("推荐mv", data);
        // console.log("id",data.data.id);
        this.getPersonalized = data.data;
      });
    },
    // getDetailFun() {
    //   getDetail({ mvid: this.mvid }).then((data) => {
    //     console.log("mv数据", data);
    //   });
    // },

    //轮播图
    getBannerFun() {
      getBanner().then((data) => {
        this.imgs = data.banners;
      });
    },
    //推荐歌单
    getPersonalizedrFun() {
      getPersonalizedr().then((data) => {
        console.log(data);
        this.Personalizedr = data.result;
      });
    },
    //推荐新歌

    newId(id) {
      console.log(id);
      this.$emit("get-player-id", this.$route.query.id);
      this.$emit("get-player-id", id);
    },
  },
  created() {
    this.getPersonalizedFun();
    this.getBannerFun(); //获取轮播图
    this.getPersonalizedrFun(); //获取推荐歌单
    this.getVideoTimelineRecommendFun();

    let queryId = this.$route.query;
    if (!("id" in queryId)) {
      // this.$router.push("/rank");
    }
    getNewSongListApi({ id: queryId.id }).then((data) => {
      console.log("推荐歌曲", data);
      this.getNewSongListApi = data.result;
    });
  },
  components: {
    headerNav,
  },
  // 过滤器
  filters: {
    playCountData(value) {
      let w = value > 10000 ? value / 10000 : value; // 万计算
      let y = w > 10000 ? parseInt(value / 10000) + "亿" : parseInt(w) + "万"; //亿计算
      return y;
    },
  },
  mounted() {
    new Swiper(".swiper-container-01", {
      // pagination: '.swiper-pagination-01',
      slidesPerView: 4, //显示个数
      paginationClickable: true,
      observer: true,
      observeParents: true,
      // spaceBetween: 30 //div之间间距
    });
    new Swiper(".swiper-container-02", {
      pagination: ".swiper-pagination-02",
      slidesPerView: 3,
      spaceBetween: 30,
      observer: true,
      observeParents: true,
    });
  },
};
</script>

<style lang="less">
.banner {
  &::before {
    content: "";
    display: block;
    height: 124px;
    background-color: #d44439;
    position: absolute;
    width: 100%;
    z-index: -1;
  }
  position: relative;
  .imgs {
    position: relative;
    left: 0px;
    right: 0px;
    top: 0px;
    margin: auto;
    width: 96%;
    border-radius: 4px;
    overflow: hidden;
    img {
      width: 100%;
    }
  }
}

.remLists {
  .title {
    height: 60px;
    line-height: 60px;
    text-indent: 5px;
    font-size: 16px;
    color: #000;
    font-weight: bold;
  }
  .content {
    ul {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;
      li {
        flex: 0 0 32%;
        position: relative;
        span {
          position: absolute;
          top: 0px;
          right: 0px;
          color: #fff;
          font-size: 10px;
          i {
            font-size: 15px;
            vertical-align: middle;
          }
        }
        .img {
          background-color: aqua;
          min-height: 50px;
          width: 100%;
          border-radius: 3px;
          img {
            width: 100%;
            border-radius: 3px;
          }
        }
        p {
          font-size: 12px;
          color: #565658;
          line-height: 15px;
          padding: 5px;
          margin-bottom: 10px;
          height: 26px;
          overflow: hidden;
        }
      }
    }
  }
}
.swiper-slide.item {
  height: 50px;
}
.result {
  .title {
    height: 60px;
    line-height: 60px;
    text-indent: 5px;
    font-size: 16px;
    color: #000;
    font-weight: bold;
  }
  .musicList {
    background-color: #fff;
    width: 100%;
    border-radius: 7px;
    position: relative;
    top: -7px;

    dt {
      height: 36px;
      line-height: 36px;
      font-size: 16px;
      color: #454747;
      border-bottom: 1px solid #e3e3e3;
      span {
        font-size: 14px;
        color: #797b7a;
      }
      i {
        width: 44px;
        text-align: center;
        display: inline-block;
      }
    }
    dd {
      border-bottom: 1px solid #e3e3e3;
      height: 53px;
      display: flex;
      h1 {
        flex: 0 0 44px;
        line-height: 53px;
        text-align: center;
        font-size: 16px;
        color: #6d6e6e;
      }
      .info {
        flex: 1;
        display: flex;
        justify-content: space-between;
        .text {
          h2 {
            font-size: 16px;
            color: #1b1c1c;
            margin-top: 10px;
          }
          h3 {
            font-size: 12px;
            color: #929393;
          }
        }
        .bofang {
          font-size: 24px;
          line-height: 53px;
          text-align: center;
          padding-right: 10px;
        }
      }
    }
  }
}
.boad{
  background: rgba(255, 255, 255);
  .video {
  .title {
    height: 60px;
    line-height: 60px;
    text-indent: 5px;
    font-size: 16px;
    color: #000;
    font-weight: bold;
  }
  .content {
    ul {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;
      li {
        flex: 0 0 32%;
        position: relative;
        span {
          position: absolute;
          top: 0px;
          right: 0px;
          color: #fff;
          font-size: 10px;
          i {
            font-size: 15px;
            vertical-align: middle;
          }
        }
        .img {
          background-color: aqua;
          min-height: 50px;
          width: 100%;
          border-radius: 3px;
          img {
            width: 100%;
            border-radius: 3px;
          }
        }
        p {
          font-size: 12px;
          color: #565658;
          line-height: 15px;
          padding: 5px;
          margin-bottom: 10px;
          height: 26px;
          overflow: hidden;
        }
      }
    }
  }
}
}

</style>